package br.com.jorganizer.model.filterrule.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import br.com.jorganizer.model.filterrule.FilterRule;
/**
 * A rule with a Regex
 * 
 * @author Luciano
 *
 */
public class RegexRule implements FilterRule{

	private String regexExpression;
	
	public RegexRule(String regexExpression) {
		
		if (regexExpression == null)
			throw new NullPointerException();
		
		if (regexExpression.isEmpty())
			throw new IllegalArgumentException("RegexExpression must be diferrent empty");

		
		this.regexExpression = regexExpression;
	}


	public boolean accepted(String filePath){
		Pattern p = Pattern.compile(regexExpression, Pattern.CASE_INSENSITIVE);
		Matcher m = p.matcher(filePath);
		return m.matches();
	}

}
